<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
    <style>
        .hd-form-upload {
            width: 80px;
            height: 80px;
            display: inline-block;
            cursor: pointer;
        }

        .hd-form-upload input {
            display: none;
        }

        .hd-form-upload span {
            width: 80px;
            height: 80px;
            line-height: 80px;
            text-align: center;
            float: left;
            overflow: hidden;
            background-color: #ddd;
        }

        .hd-form-upload span img {
            width: 100%;
            display: inline;
            vertical-align: middle;
        }

        .hd-form-upload span i {
            width: 80px;
            height: 80px;
            float: left;
            position: relative;
        }

        .hd-form-upload  span i:before {
            content: "";
            border-top: 2px solid #bbb;
            position: absolute;
            top: 39px;
            left: 20px;
            right: 20px;
        }

        .hd-form-upload  span i:after {
            content: "";
            border-right: 2px solid #bbb;
            position: absolute;
            top: 20px;
            left: 39px;
            bottom: 20px;
        }
    </style>
</head>
<body>
<form class="layui-form">
    <div class="mainBox  layui-card-body" style="padding: 0 0;">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">调研标题*</label>
                <div class="layui-input-block">
                    <input type="text" name="title" lay-verify="required" placeholder="请输入调研标题" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开放状态*</label>
                <div class="layui-input-block">
                    <select name="open_up">
                        <option value="1">全部开放</option>
                        <option value="2">仅开放1flex</option>
                        <option value="3">仅开放openflex</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">open flex选课数*</label>
                <div class="layui-input-block">
                    <input type="number" name="number" autocomplete="off" placeholder="请填写open flex选课数" value="1" min="0" max="999" class="layui-input">
                </div>
                <p style="margin-left:130px;">
                    open flex设置选课数量 0=不限制
                </p>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">调研范围*</label>
                <div class="layui-input-block">
                    <select name="range">
                        <option value="1">所有选课商城用户</option>
                        <option value="3">指定学员开放</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">调研日期*</label>
                <div class="layui-input-block">
                    <input type="text" name="time" lay-verify="required" id="date" autocomplete="off" placeholder="请选择调研日期" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">背景主题*</label>
                <div class="layui-input-block">
                    <a class="pear-btn" onclick="show()">选择</a>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <label class="hd-form-upload">
                        <span id="thumb-background-thumb">
                            <i></i>
                        </span>
                    </label>
                </div>
            </div>
            <input type="hidden" name="background" id="background_thumb">
			
			
			  <div class="layui-form-item">
                <label class="layui-form-label">背景_PC*</label>
                <div class="layui-input-block">
                    <label class="hd-form-upload" id="image">
                        <span id="thumb-img-thumb">
                                <i></i>
                        </span>
                    </label>
                    <input type="hidden" id="img_thumb_pc" name="background_pc" value=""/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">背景icon*</label>
                <div class="layui-input-block">
                    <label class="hd-form-upload" id="icon">
                        <span id="thumb-icon-thumb">
                            <i></i>
                        </span>
                    </label>
                </div>
                <p style="margin-left:130px;">
                    icon大小64*64
                </p>
            </div>
            <input type="hidden" name="icon" id="icon_thumb">
            {:token_field()}
        </div>
    </div>


    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{include file="_Fragment/javascript" /}
<script src="/static/common/jquery-3.6.0.min.js"></script>
<script>
    function show() {
        layer.open({
            type: 2,
            title: '选择背景主题',
            shade: 0.1,
            area: ['800px', '500px'],
            content: '/Flex/showBackground'
        });
    }

    layui.use(['form', 'jquery', 'element', 'upload'], function() {
        let form = layui.form;
        let upload = layui.upload;
        let laydate = layui.laydate;
        let $ = layui.jquery;

        laydate.render({
            elem: '#date'
            ,range: true //或 range: '~' 来自定义分割字符
            ,trigger: 'click'
            ,type: 'datetime'
        });

        upload.render({
            elem: '#icon'
            ,url: "{:url('Pub/blob')}"
            ,accept:'images'
            ,acceptMime: 'image/*'
            ,exts:'jpeg|jpg|png'
            ,done: function(res){
                if(res.code == 200){
                    $("#thumb-icon-thumb").html('<img src="'+ res.data + '" />');
                    $("#icon_thumb").val(res.data);
                } else {
                    layer.msg(res.msg);
                }
            }
        });
		
		   upload.render({
            elem: '#image'
            ,url: "{:url('Pub/blob')}"
            ,accept:'images'
            ,acceptMime: 'image/*'
            ,exts:'jpeg|jpg|png'
            ,done: function(res){
                if(res.code == 200){
                    $("#thumb-img-thumb").html('<img src="'+ res.data + '" />');
                    $("#img_thumb_pc").val(res.data);
                } else {
                    layer.msg(res.msg);
                }
            }
        });

        form.on('submit(user-save)', function(data) {
            let loading = layer.load();
            $.ajax({
                url: '/Flex/save',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    layer.close(loading);
                    if (result.status == 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>